package com.example.dogliving.homemodle;


import com.example.dogliving.bean.HomeBean;
import com.example.dogliving.interfaces.IViewPager;
import com.example.dogliving.utils.Constant;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by 张昭 on 2016/12/22.
 */

public class HomeModle implements IHomeModle{
    //首页秀场解析
    @Override
    public void login(final OnLoadHomeListener loadSearchListener) {
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl(Constant.URL_Home)
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        IViewPager iViewPager=retrofit.create(IViewPager.class);
        Observable<HomeBean> observable=iViewPager.getHomeBean();
        observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<HomeBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                    loadSearchListener.onFailed(e);
                    }

                    @Override
                    public void onNext(HomeBean homeBean) {
                    loadSearchListener.onSucess(homeBean);
                    }
                });
    }
}
